<!--
 * @Description: 活动 - 临期商品审核
 * @Author: liyujie
 * @Date: 2021/04/14
 * @Last Modified by: liyujie
 * @Last Modified time: 2021/04/14
-->
<template>
    <div class="wrapper">
        <div class="content-wrapper">
            <!-- header -->
            <div class="header">
                <div class="header-title">
                    倒计食
                </div>
                <div class="add-btn">
                    <el-button
                        type="primary"
                        size="medium"
                        icon="el-icon-plus"
                        @click="handleRoute('adventGoodsAdd')"
                    >
                        添加商品
                    </el-button>
                    <el-button
                        type="primary"
                        size="medium"
                        @click="configGoodsType"
                    >
                        活动设置
                    </el-button>
                </div>
            </div>
            <el-tabs
                v-model="filterData.verify"
                @tab-click="getTableData(1)"
            >
                <el-tab-pane
                    label="全部"
                    name="99"
                />
                <el-tab-pane
                    label="待审核"
                    name="0"
                />
                <el-tab-pane
                    label="审核通过"
                    name="1"
                />
                <el-tab-pane
                    label="审核不通过"
                    name="-1"
                />
            </el-tabs>
            <!-- /header -->
            <!-- 筛选-->
            <div class="filter-view">
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        商品信息
                    </p>
                    <el-input
                        placeholder="搜索商品编号，商品名称"
                        v-model="filterData.keyword"
                        suffix-icon="el-icon-search"
                        clearable
                        size="medium"
                        style="width: 240px"
                        @keydown.enter.native="getTableData(1)"
                    />
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        店铺名称
                    </p>
                    <el-input
                        placeholder="搜索店铺名称"
                        v-model="filterData.shop_title"
                        suffix-icon="el-icon-search"
                        clearable
                        size="medium"
                        style="width: 240px"
                        @keydown.enter.native="getTableData(1)"
                    />
                </div>

                <div class="header-new-box">
                    <el-button
                        type="primary"
                        size="small"
                        @click="getTableData(1)"
                    >
                        查询
                    </el-button>
                </div>
            </div>
            <!--筛选-->

            <!-- table -->
            <div class="table-wrapper">
                <el-table
                    :data="tableData"
                    height="100%"
                    style="width: 100%;"
                    ref="tempLateName"
                    class="data-table"
                    v-loading="tableLoading"
                    row-key="exp_no"
                    @selection-change="handleSelectedChange"
                >
                    <el-table-column
                        align="center"
                        width="50"
                        type="selection"
                        fixed="left"
                        reserve-selection
                        :selectable="canSelect"
                    />
                    <el-table-column
                        label="序号"
                        align="center"
                        width="50"
                        type="index"
                        fixed="left"
                    />
                    <el-table-column
                        width="320"
                        label="商品信息"
                        fixed="left"
                    >
                        <template slot-scope="scope">
                            <div class="goods-info">
                                <img
                                    :src="scope.row.goods_cover"
                                    class="goods-cover"
                                    @click="fnShowPreview(scope.row.goods_cover)"
                                >
                                <div class="info">
                                    <div class="goods-info__title">
                                        {{ scope.row.goods_title }}
                                    </div>
                                    <div class="goods-info__no">
                                        商品编号：{{ scope.row.goods_no }}
                                    </div>
                                    <div class="goods-info__shop-title">
                                        店铺名称：{{ scope.row.shop_title }}
                                    </div>
                                </div>
                            </div>
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="生产日期"
                        show-overflow-tooltip
                        align="center"
                        width="120"
                        :formatter="emptyFormatter"
                    >
                        <template slot-scope="scope">
                            <el-button
                                type="text"
                                @click="showPriceDialog(scope.row)"
                            >
                                查看
                            </el-button>
                        </template>
                    </el-table-column>
                    <el-table-column
                        prop="exp_days"
                        label="保质期(天)"
                        show-overflow-tooltip
                        align="center"
                        width="110"
                        :formatter="emptyFormatter"
                    />
                    <el-table-column
                        label="剩余保质期"
                        show-overflow-tooltip
                        align="center"
                        width="120"
                        :formatter="emptyFormatter"
                    >
                        <template slot-scope="scope">
                            <el-button
                                type="text"
                                @click="showPriceDialog(scope.row)"
                            >
                                查看
                            </el-button>
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="到期时间"
                        show-overflow-tooltip
                        align="center"
                        :formatter="emptyFormatter"
                    >
                        <template slot-scope="scope">
                            <el-button
                                type="text"
                                @click="showPriceDialog(scope.row)"
                            >
                                查看
                            </el-button>
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="保质期剩余150天活动价（元）"
                        show-overflow-tooltip
                        align="center"
                        width="120"
                        :formatter="emptyFormatter"
                    >
                        <template slot-scope="scope">
                            {{ scope.row.min_price_150 }}起
                            <el-button
                                type="text"
                                @click="showPriceDialog(scope.row)"
                            >
                                查看
                            </el-button>
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="保质期剩余90天活动价（元）"
                        show-overflow-tooltip
                        align="center"
                        width="120"
                        :formatter="emptyFormatter"
                    >
                        <template slot-scope="scope">
                            {{ scope.row.min_price_90 }}起
                            <el-button
                                type="text"
                                @click="showPriceDialog(scope.row)"
                            >
                                查看
                            </el-button>
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="保质期剩余60天活动价（元）"
                        show-overflow-tooltip
                        align="center"
                        width="120"
                        :formatter="emptyFormatter"
                    >
                        <template slot-scope="scope">
                            {{ scope.row.min_price_60 }}起
                            <el-button
                                type="text"
                                @click="showPriceDialog(scope.row)"
                            >
                                查看
                            </el-button>
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="原售价（元）"
                        show-overflow-tooltip
                        align="center"
                        width="120"
                        :formatter="emptyFormatter"
                    >
                        <template slot-scope="scope">
                            {{ scope.row.min_product_price }}起
                            <el-button
                                type="text"
                                @click="showPriceDialog(scope.row)"
                            >
                                查看
                            </el-button>
                        </template>
                    </el-table-column>
                    <el-table-column
                        prop="commission_rate"
                        label="佣金比例（%）"
                        show-overflow-tooltip
                        align="center"
                        width="120"
                        :formatter="emptyFormatter"
                    />
                    <el-table-column
                        prop="total_stock"
                        label="活动设置库存"
                        show-overflow-tooltip
                        align="center"
                        width="110"
                        :formatter="emptyFormatter"
                    >
                        <template slot-scope="scope">
                            {{ scope.row.total_stock }}
                            <el-button
                                type="text"
                                @click="showPriceDialog(scope.row)"
                            >
                                查看
                            </el-button>
                        </template>
                    </el-table-column>
                    <el-table-column
                        prop="total_rest_stock"
                        label="活动剩余库存"
                        show-overflow-tooltip
                        align="center"
                        width="110"
                        :formatter="emptyFormatter"
                    >
                        <template slot-scope="scope">
                            {{ scope.row.total_rest_stock }}
                            <el-button
                                type="text"
                                @click="showPriceDialog(scope.row)"
                            >
                                查看
                            </el-button>
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="商家库存"
                        show-overflow-tooltip
                        align="center"
                        width="110"
                        :formatter="emptyFormatter"
                    >
                        <template slot-scope="scope">
                            <el-button
                                type="text"
                                @click="showPriceDialog(scope.row)"
                            >
                                查看
                            </el-button>
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="报名来源"
                        show-overflow-tooltip
                        align="center"
                        :formatter="emptyFormatter"
                    >
                        <template slot-scope="scope">
                            {{ scope.row.from_type === 1 ? '平台报名' : '商家报名' }}
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="排序"
                        show-overflow-tooltip
                        align="center"
                        width="120"
                        :formatter="emptyFormatter"
                    >
                        <template slot-scope="scope">
                            <div class="sort-wrap">
                                {{ scope.row.sort }}
                                <span class="sort-spliter" />
                                <el-button
                                    type="text"
                                    class="btn-sort"
                                    :disabled="scope.row.verify === -1"
                                    @click="editSort(scope.row)"
                                >
                                    <i class="el-icon-edit" />
                                </el-button>
                            </div>
                        </template>
                    </el-table-column>
                    <el-table-column
                        prop="sale_num"
                        label="活动销量"
                        show-overflow-tooltip
                        align="center"
                    />
                    <el-table-column
                        prop="app_sale_num"
                        label="APP显示销量"
                        show-overflow-tooltip
                        align="center"
                        width="110"
                    />
                    <el-table-column
                        label="创建时间"
                        align="left"
                        :formatter="emptyFormatter"
                        min-width="160"
                    >
                        <template slot-scope="scope">
                            {{ scope.row.create_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm:ss') }}
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="限购数量"
                        show-overflow-tooltip
                        align="center"
                        :formatter="emptyFormatter"
                    >
                        <template slot-scope="scope">
                            <el-button
                                type="text"
                                @click="showPriceDialog(scope.row)"
                            >
                                查看
                            </el-button>
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="参与活动时间"
                        align="left"
                        :formatter="emptyFormatter"
                        min-width="180"
                    >
                        <template slot-scope="scope">
                            <div v-if="scope.row.activity_end_time">
                                {{ scope.row.activity_start_time * 1000 | dateFormatter('yyyy/MM/dd') }} -
                                {{ scope.row.activity_end_time * 1000 | dateFormatter('yyyy/MM/dd') }}
                            </div>
                            <div v-else-if="scope.row.activity_start_time && !scope.row.activity_end_time">
                                {{ scope.row.activity_start_time * 1000 | dateFormatter('yyyy/MM/dd') }} - 长期
                            </div>
                            <div v-else>--</div>
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="审核状态"
                        width="134"
                        :formatter="emptyFormatter"
                    >
                        <template slot-scope="scope">
                            <div
                                class="status-wrapper"
                                :class="scope.row.verify === 0 ? 'warning' : scope.row.verify === 1 ? 'success' : 'normal'"
                            >
                                {{ scope.row.verify | verifyStatusFilter }}
                                <!--<el-button
                                    type="text"
                                    v-if="scope.row.verify === -1"
                                    @click="showRejectDialog(scope.row, 1)"
                                >
                                    (查看原因)
                                </el-button>-->
                            </div>

                        </template>
                    </el-table-column>
                    <el-table-column
                        label="活动状态"
                        align="center"
                        :formatter="emptyFormatter"
                    >
                        <template slot-scope="scope">
                            <div
                                class="status-wrapper"
                                :class="scope.row.status === 0 ? 'danger' : scope.row.status === 1 ? 'success' : 'normal'"
                            >
                                {{ scope.row.status | statusFilter }}
                            </div>
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="操作"
                        align="left"
                        width="180"
                        fixed="right"
                    >
                        <template slot-scope="scope">
                            <div class="option-btn-group">
                                <el-button
                                    type="text"
                                    :disabled="scope.row.verify !== 0"
                                    @click="showPassDialog(scope.row)"
                                >
                                    通过
                                </el-button>
                                <el-button
                                    type="text"
                                    :disabled="scope.row.verify === -1"
                                    @click="showRejectDialog(scope.row)"
                                >
                                    不通过
                                </el-button>
                                <el-button
                                    type="text"
                                    :disabled="scope.row.verify === -1"
                                    @click="handleEdit(scope.row)"
                                >
                                    编辑
                                </el-button>
                            </div>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
            <!-- /table -->

            <!-- /分页 -->
            <div class="pagination-wrapper clearfix">
                <div class="op-view">
                    <el-checkbox
                        label="当页全选"
                        v-model="checkAllStatus"
                        :indeterminate="checkIndeterminate"
                        :disabled="tableData.length === 0"
                        @change="handleSelectedAll"
                    />
                    <el-button
                        type="text"
                        size="medium"
                        style="margin-left: 12px"
                        :disabled="multipleSelection.length === 0"
                        @click="handleVerifyBatch"
                    >
                        批量通过
                    </el-button>
                    <el-pagination
                        layout="total, prev, pager, next, jumper"
                        background
                        :current-page.sync="page.now_page"
                        :total="page.total_count"
                        :page-size="page.page_size"
                        @current-change="getTableData"
                    />
                </div>
            </div>
        </div>

        <!-- 查看价格弹窗 -->
        <el-dialog
            title="查看商品"
            :visible.sync="productVisible"
            width="1400px"
            :close-on-click-modal="false"
        >
            <el-table
                :data="detailRow.product_list"
                height="100%"
                style="width: 100%;max-height: 450px"
                class="data-table"
            >
                <el-table-column
                    prop="spec_list"
                    label="规格名称"
                    show-overflow-tooltip
                    :formatter="emptyFormatter"
                    width="150"
                >
                    <template slot-scope="scope">
                        {{ scope.row.spec_list | filterSpec }}
                    </template>
                </el-table-column>
                <el-table-column
                    label="生产日期"
                    show-overflow-tooltip
                    align="center"
                    width="100"
                    :formatter="emptyFormatter"
                >
                    <template slot-scope="scope">
                        {{ scope.row.production_time * 1000 | dateFormatter('yyyy/MM/dd') }}
                    </template>
                </el-table-column>
                <el-table-column
                    label="保质期(天)"
                    show-overflow-tooltip
                    align="center"
                    width="100"
                    :formatter="emptyFormatter"
                >
                    <template slot-scope="scope">
                        {{ detailRow.exp_days }}
                    </template>
                </el-table-column>
                <el-table-column
                    label="剩余保质期"
                    show-overflow-tooltip
                    align="center"
                    width="100"
                    :formatter="emptyFormatter"
                >
                    <template slot-scope="scope">
                        {{ calcExpRestDays(scope.row, detailRow.exp_days) }}
                    </template>
                </el-table-column>
                <el-table-column
                    label="到期时间"
                    show-overflow-tooltip
                    align="center"
                    width="100"
                    :formatter="emptyFormatter"
                >
                    <template slot-scope="scope">
                        {{ calcExpDate(scope.row, detailRow.exp_days) }}
                    </template>
                </el-table-column>
                <el-table-column
                    prop="price_150"
                    label="保质期剩余150天活动价(元)"
                    show-overflow-tooltip
                    align="center"
                    width="120"
                    :formatter="emptyFormatter"
                />
                <el-table-column
                    prop="price_90"
                    label="保质期剩余90天活动价(元)"
                    show-overflow-tooltip
                    align="center"
                    width="120"
                    :formatter="emptyFormatter"
                />
                <el-table-column
                    prop="price_60"
                    label="保质期剩余60天活动价(元)"
                    show-overflow-tooltip
                    align="center"
                    width="120"
                    :formatter="emptyFormatter"
                />
                <el-table-column
                    prop="product_price"
                    label="原售价(元)"
                    show-overflow-tooltip
                    align="center"
                    width="100"
                    :formatter="emptyFormatter"
                />
                <el-table-column
                    prop="buy_limit_count"
                    label="限购数量"
                    show-overflow-tooltip
                    align="center"
                    :formatter="emptyFormatter"
                >
                    <template slot-scope="scope">
                        {{ scope.row.buy_limit_count === -1 ? '不限' : scope.row.buy_limit_count }}
                    </template>
                </el-table-column>
                <el-table-column
                    prop="stock_origin"
                    label="活动设置库存"
                    show-overflow-tooltip
                    align="center"
                />
                <el-table-column
                    prop="stock"
                    label="活动剩余库存"
                    show-overflow-tooltip
                    align="center"
                />
                <el-table-column
                    prop="product_stock"
                    label="商家库存"
                    show-overflow-tooltip
                    align="center"
                />
            </el-table>
            <span
                slot="footer"
                class="dialog-footer"
            >
                <el-button
                    @click="productVisible = false"
                    size="medium"
                    type="primary"
                >
                    我知道了
                </el-button>
            </span>
        </el-dialog>
        <!-- 驳回弹窗 -->
        <reject-dialog
            ref="rejectDialog"
            :visible.sync="rejectDialog"
            :reason-detail="reasonDetail"
            :maxlength="100"
            @confirm="handleExamine(exp_no,'reject', $event)"
        />
        <!-- /驳回弹窗 -->
        <!-- 分类弹窗 -->
        <goods-type-select
            ref="goodsTypeSelect"
            @confirm="handleConfig"
        />
        <!-- 图片预览 -->
        <img-preview
            ref="preview"
        />
    </div>
</template>

<script>
import { back } from '@/mixin/back';
import ImgPreview from "@/components/common/img-preview";
import RejectDialog from "@/components/dialog/reject-dialog";
import GoodsTypeSelect from "@/components/goods/goods-type-select";

export default {
    name: 'AdventGoodsVerify',
    mixins: [back],
    components: {GoodsTypeSelect, RejectDialog, ImgPreview},
    data() {
        return {
            filterData: {
                verify: '99',
                // 活动信息
                keyword: '',
                shop_title: ''
            },
            tableData: [],
            tableLoading: false,
            page: {
                now_page: 1,
                total_count: 0,
                page_size: 20
            },
            statusList: [
                {label: '全部', value: 99},
                {label: '已上架', value: 1},
                {label: '已下架', value: 0},
            ],
            // 价格弹窗
            productVisible: false,
            detailRow: {},
            exp_no: '',
            rejectDialog: false,
            reasonDetail: '',
            checkAllStatus: false,
            checkIndeterminate: false,
            multipleSelection: []
        };
    },
    computed: {},
    watch: {},
    filters: {
        verifyStatusFilter(val) {
            switch (val) {
                case 0:
                    return '待审核';
                case 1:
                    return '已通过';
                case -1:
                    return '未通过';
                case -2:
                    return '取消报名';
                default:
                    return '--';
            }
        },
        statusFilter(val) {
            switch (val) {
                case 0:
                    return '未开始';
                case 1:
                    return '进行中';
                case 2:
                    return '已结束';
                default:
                    return '--';
            }
        },
        filterSpec (val) {
            if(!val) return '';
            let str = '';

            val.forEach(el => {
                str += el.spec_name + ':' + el.spec_value + ';';
            });
            return str;
        }
    },
    mounted() {
        this.$store.commit('SET_HEADER', [{title: "APP后台"}, {title: '商城'}, {title: '活动管理'}, {title: '倒计食'}]);
        this.authResult = this.$route.meta.authResult;
        this.getTableData();
    },

    methods: {

        /**
         * @description 获取列表数据
         * @param page
         */
        getTableData(page) {
            this.tableLoading = true;
            let params = { ...this.filterData };

            params.page_id = page || this.page.now_page;
            this.$post('/student/shop_goods_activity_near_exp%5Cget_list', params, res => {
                if (res.code === 1) {
                    this.tableData = res.data.list;
                    this.page = res.data.page;
                } else {
                    this.$notify({
                        title: '提示',
                        message: res.msg,
                        type: 'warning'
                    });
                }
                this.tableLoading = false;
            });
        },

        /**
         * 路由跳转
         * @param routeName
         * @param query
         */
        handleRoute(routeName, query) {
            this.$router.push({
                name: routeName,
                query
            });
        },

        /**
         * @description 过滤函数
         */
        emptyFormatter(row, column, val) {
            if (!val) return '--';
            return val;
        },

        /**
         * 编辑
         * @param row
         * @returns {boolean}
         */
        handleEdit(row) {
            let url = this.$shopBaseUrl;

            this.$post('/wei4/hire_user%5Cget_login_session_ticket', {hire_no: row.hire_no}, resp => {
                if (resp.code === 1) {
                    window.open(`${url}/manage/active/active-promotion-submit?exp_no=${row.exp_no}&type=edit&session_ticket=${resp.data.session_ticket}`);
                } else {
                    this.$notify({
                        title: '提示',
                        type: 'warning',
                        message: resp.msg
                    });
                }
            });
        },

        /**
         * 预览图片
         * @param   {String}    images      //单图预览
         * @param   {Array}     images      //多图预览
         * @param index
         */
        fnShowPreview(images, index) {
            if (images && Object.prototype.toString.call(images) == '[object String]') {
                this.$refs.preview.show([
                    images
                ]);
            } else if (images && Object.prototype.toString.call(images) == '[object Array]') {
                this.$refs.preview.show(images, index);
            } else {
                this.$message({
                    type: 'warning',
                    message: '图片类型错误'
                });
            }
        },

        /**
         * 显示详细价格弹窗
         * @param row
         */
        showPriceDialog(row) {
            this.productVisible = true;
            this.detailRow = row;
        },

        /**
         * 计算到期时间
         * @param row
         * @param days
         */
        calcExpDate(row, days) {
            return this.$moment(row.production_time * 1000).add(days, 'days').format('YYYY/MM/DD');
        },

        /**
         * 计算剩余保质期
         * @param row
         * @param days
         */
        calcExpRestDays(row, days) {
            let now = Number(this.$moment().format('x'));
            let exp_date = Number(this.$moment(row.production_time * 1000).add(days, 'days').format('x'));

            return Math.round((exp_date - now) / (1000 * 3600 * 24));
        },

        /**
         * 排序修改
         */
        editSort (row) {
            this.$prompt('请输入排序号', '排序', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                inputPattern: /^([1-9]\d?|[1-9]\d+)$/,
                inputErrorMessage: '排序号格式不正确,请重新输入',
                inputValue: row.sort
            }).then(({ value }) => {
                let params = {
                    exp_no: row.exp_no,
                    sort: value
                };

                this.$post('/student/shop_goods_activity_near_exp%5CsetSort', params ,resp=>{
                    if (resp.code === 1) {
                        this.getTableData();
                        this.$notify({
                            title: '提示',
                            type: 'success',
                            message: '设置成功'
                        });
                    } else {
                        this.$notify({
                            title: '提示',
                            type: 'warning',
                            message: resp.msg
                        });
                    }
                });
            });
        },

        /**
         * 审核通过提示弹窗
         * @param row
         */
        showPassDialog(row) {
            if(!this.authResult.auth_verify) {
                this.$notify({
                    title: '提示',
                    message: '请联系管理员添加权限',
                    type: 'warning',
                    duration: 2000
                });
                return false;
            }
            this.$confirm('是否确认通过审核?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.handleExamine(row.exp_no, 'pass');
            });
        },

        /**
         * 驳回弹窗
         * @param type - 0填写驳回原因  1回显原因
         * @param row
         */
        showRejectDialog(row, type = 0) {
            if(type === 1) {
                // 回显
                this.reasonDetail = row.verify_fail_reason;
                this.rejectDialog = true;
            } else {
                if(!this.authResult.auth_verify) {
                    this.$notify({
                        title: '提示',
                        message: '请联系管理员添加权限',
                        type: 'warning',
                        duration: 2000
                    });
                    return false;
                }
                // 填写
                this.exp_no = row.exp_no;
                this.$refs.rejectDialog.title = '审核驳回';
                this.reasonDetail = '';
                this.rejectDialog = true;
            }
        },

        /**
         * 审核
         * @param action - pass通过  reject拒绝
         * @param reason - 拒绝原因
         * @param exp_no - 编号
         */
        handleExamine(exp_no, action, reason = '') {
            let params = {
                exp_no,
                verify_fail_reason: reason,
                action: action === 'pass' ? 1 : -1
            };

            this.$post('/student/shop_goods_activity_near_exp%5Caudit', params, resp => {
                if (resp.code === 1) {
                    this.rejectDialog = false;
                    this.getTableData();
                    this.$notify({
                        title: '成功',
                        message: '操作成功',
                        duration: 2000,
                        type: 'success'
                    });
                } else {
                    this.$notify({
                        title: '提示',
                        message: resp.msg,
                        duration: 2000,
                        type: 'warning'
                    });
                }
            });
        },

        /**
         * 活动设置
         */
        configGoodsType() {
            if(!this.authResult.auth_config) {
                this.$notify({
                    title: '提示',
                    message: '请联系管理员添加权限',
                    type: 'warning',
                    duration: 2000
                });
                return false;
            }

            this.$post('/student/shop_goods_activity_near_exp%5Cget_config', {}, resp => {
                if (resp.code === 1) {
                    this.$refs.goodsTypeSelect.show(resp.data);
                } else {
                    this.$notify({
                        title: '提示',
                        message: resp.msg,
                        duration: 2000,
                        type: 'warning'
                    });
                }
            });
        },

        /**
         * 设置活动
         */
        handleConfig(data) {
            this.$post('/student/shop_goods_activity_near_exp%5Cset_config', {type_json: JSON.stringify(data)}, resp => {
                if (resp.code === 1) {
                    // this.getTableData();
                    this.$notify({
                        title: '成功',
                        message: '操作成功',
                        duration: 2000,
                        type: 'success'
                    });
                } else {
                    this.$notify({
                        title: '提示',
                        message: resp.msg,
                        duration: 2000,
                        type: 'warning'
                    });
                }
            });
        },

        /**
         * 点击全选
         * @param val
         */
        handleSelectedAll(val) {
            if(val) {
                this.$refs.tempLateName.toggleAllSelection();
            } else {
                this.$refs.tempLateName.clearSelection();
            }
            this.checkIndeterminate = false;
        },

        /**
         * 批量审核通过
         */
        handleVerifyBatch() {
            this.$confirm('是否确认通过审核?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                let exp_no_str = this.multipleSelection.map(item => {
                    return item.exp_no;
                }).join();

                this.$post('/student/shop_goods_activity_near_exp%5Caudit_batch', { exp_no_str }, resp => {
                    if (resp.code === 1) {
                        this.getTableData();
                        this.$refs.tempLateName.clearSelection();
                        this.$notify({
                            title: '成功',
                            message: '操作成功',
                            duration: 2000,
                            type: 'success'
                        });
                    } else {
                        this.$notify({
                            title: '提示',
                            message: resp.msg,
                            duration: 2000,
                            type: 'warning'
                        });
                    }
                });
            }).catch(() => {});

        },

        /**
         * 选中
         * @param selection
         */
        handleSelectedChange(selection) {
            let checkedCount = selection.length;

            this.multipleSelection = selection;
            this.checkAllStatus = checkedCount === this.tableData.length;
            this.checkIndeterminate = checkedCount > 0 && checkedCount < this.tableData.length;
        },

        /**
         * 是否可选择
         */
        canSelect(row) {
            return row.verify === 0;
        }
    }
};
</script>

<style lang="less" scoped>
.wrapper {
    width: 100%;

    .content-wrapper {
        display: flex;
        height: calc(100% - 24px);
        flex-direction: column;
        position: relative;
        margin: 12px;
        background: #fff;
        box-sizing: border-box;

        /*el-tabs*/

        /deep/ .el-tabs {
            .el-tabs__nav-wrap {
                height: 54px;
                padding-left: 24px;

                .el-tabs__nav-scroll {
                    .el-tabs__nav {
                        height: 54px;
                        line-height: 54px;
                    }
                }
            }
        }

        /*header*/

        .header {
            height: 68px;
            padding: 24px;
            box-sizing: border-box;
            box-shadow: 0px -1px 0px 0px #F0F2F5;
            display: flex;
            align-items: center;
            justify-content: space-between;

            .header-title {
                color: #333333;
                font-size: 20px;
                height: 20px;
                font-weight: 500;
                position: relative;
                margin: 24px 0 24px 12px;

                &::before {
                    content: '';
                    position: absolute;
                    left: -8px;
                    top: -1px;
                    width: 3px;
                    height: 20px;
                    background: #1890FF;
                }
            }
        }

        /*筛选*/

        .filter-view {
            box-sizing: border-box;
            display: flex;
            align-items: center;
            flex-wrap: wrap;
            padding: 0 24px;

            .header-new-box {
                display: flex;
                align-items: center;
                font-family: PingFangSC-Regular, PingFang SC;
                font-weight: 400;
                color: #333333;
                white-space: nowrap;
                margin-right: 24px;
                margin-bottom: 12px;

                &-title {
                    margin-right: 16px;
                    white-space: nowrap;
                }
            }
        }

        // 表格
        .table-wrapper {
            padding: 0 24px;
            flex: 1;
            height: 0;
        }

        .goods-info {
            display: flex;
            align-items: center;
            .goods-cover {
                width: 68px;
                height: 68px;
                cursor: pointer;
                margin-right: 16px;
                flex-shrink: 0;
            }
            .info {
                display: flex;
                flex-direction: column;
                justify-content: space-between;
                font-size: 12px;
                font-family: PingFangSC-Regular, PingFang SC;
                font-weight: 400;
                color: #333333;
                .goods-info__title {
                    font-size: 14px;
                    cursor: pointer;
                    display: -webkit-box;
                    -webkit-box-orient: vertical;
                    overflow: hidden;
                    -webkit-line-clamp: 2;
                }
            }
        }

        .status-wrapper {
            position: relative;
            text-align: center;
            display: flex;
            align-items: center;
            padding-left: 4px;
            &.danger::before {
                background: #FF3030;
            }
            &.success::before {
                background: #4CD964;
            }
            &.warning::before {
                background: #FFA72D;
            }
            &.normal::before {
                background: #C2C2C2;
            }
            &::before {
                content: "";
                position: absolute;
                top: 50%;
                left: -10px;
                transform: translate(0, -50%);
                width: 6px;
                height: 6px;
                border-radius: 50%;
            }
        }

        /* 排序 */
        .sort-wrap {
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            .sort-spliter {
                width: 1px;
                height: 12px;
                background: rgba(235, 235, 235, 1);
                margin: 0 10px;
            }
            .btn-sort {
                font-size: 14px;
                line-height: 1;
                color: #ccc;
                &:hover {
                    color: #20a0ff;
                }
            }
        }

        /* 分页 */

        .pagination-wrapper {
            padding: 12px 24px;
            .el-pagination {
                float: right;
                padding: 0;
                background-color: transparent;
            }
        }
    }
    /deep/ .el-dialog__header {
        padding-top: 10px;
        box-shadow:0 1px 0 0 rgba(233,233,233,1);
        display: flex;
        align-items: center;
        background: #FAFAFA;
        border-radius: 4px 4px 0 0;
        .el-dialog__title {
            font-weight: 500;
            color: #333;
            font-size: 14px;
        }
        .el-icon-close:before {
            color: rgb(194,194,194);
            font-size: 17px;
            font-weight: bold;
        }
        .el-dialog__headerbtn {
            top: 14px;
        }
    }
    .dialog-footer {
        display: flex;
        justify-content: center;
    }
    /deep/ .el-textarea__inner {
        resize: none;
    }
    /deep/ .el-table__fixed-right {
        right: 6px!important;
    }
    .data-table {
        ::-webkit-scrollbar {
            width: 6px;
            height: 6px;
        }
        // 操作按钮
        .option-btn-group {
            .el-button {
                margin-left: 0;
                margin-right: 10px;
            }
        }
    }
}
</style>
